package com.jiusem.cordova.setup;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;

import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.widget.Toast;

public class Setup extends CordovaPlugin{
	

	public boolean execute(String action , JSONArray args, CallbackContext callbackContext ){
		
		if(action.equals("open")){
			String type = null;
			try {
				type = args.getString(0);
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			this.open(type);
		}
		
		return true;
	}
	
	public void open(String type){
		String action = null ;
		if(type.equals("setup")){
			action = Settings.ACTION_SETTINGS;
		}else if(type.equals("wifi")){
			action = Settings.ACTION_WIFI_SETTINGS;
		}
		Intent intent = new Intent(action);
		this.cordova.getActivity().startActivity(intent);
	}
	
	public void toast(String text){
		Context Activity = this.cordova.getActivity().getApplicationContext();
		Toast.makeText(Activity, text, Toast.LENGTH_LONG).show();
	}
	
}
